<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-2.1.0.min.js"></script>
    <script>
        function fn1() {
            $.get(
                "/ajaxservlet2", //url
                // "name=zhangsan&age=11",//提交的数据
                {"name": "李武", "sex": "男"},
                function (data) {//回调函数
                    // alert(data);
                    alert(data.name + "\n" + data.hobby)
                },
                "json" //返回的数据类型
            );
        }

        function fn2() {
            $.post(
                "/ajaxservlet2", //url
                // "name=zhangsan&age=11",//提交的数据
                {"name": "王小络", "sex": "女"},
                function (data) {//回调函数
                    // alert(data);
                    alert(data.name + "\n" + data.hobby)
                },
                "json" //返回的数据类型
            );
        }

        function fn3() {
            $.ajax(
                {
                    "url":"/ajaxservlet2",
                    "async":true,
                    "error": "请求失败",
                    "data":{"name": "汪洋", "sex": "男"},
                    "dataType":"json",
                    "success":function (data) {
                        alert(data.name + "\n" + data.hobby)
                    },
                    "type":"get"
                }
            );
        }
    </script>
</head>
<body>
<input type="button" value="get请求提交参数" onclick="fn1()">
<br>
<input type="button" value="post请求提交参数" onclick="fn2()">
<br>
<input type="button" value="ajax访问服务器" onclick="fn3()">
<br>
</body>
</html>